//    https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4



class Solution
{
public:
    int maxLength(vector<int>& arr)
    {
        set<int> s;
        int l = 0, r = 0;
        int ans = 0;
        while (l < arr.size() && r < arr.size())
        {
            if (!s.count(arr[r]))
            {
                s.insert(arr[r]);
                r++;
                ans = max(ans, r - l);
            }
            else
            {
                s.insert(arr[r]);
                s.erase(arr[l]);
                l++;
            }
        }
        return ans;
    }
};